/**
* @Author: zmx
* @Date: 2023/10/9
* @Description:
*/
<template>
  <div ref="artRef"></div>
</template>

<script>

export default {
  data() {
    return {
      instance: null,
    };
  },
  props: {
    option: {
      type: Object,
      required: true,
    },
    cream:{
      type: Boolean,
      required: true,
    }
  },
  mounted() {
    console.log(this.cream,'mmm')
    this.instance = new Artplayer({
      ...this.option,
      screenshot: this.cream,//截图
      container: this.$refs.artRef,
    });
    this.instance.on('ready',()=>{
      this.instance.on('screenshot', async () => {
        const url = await this.instance.getDataURL();
        this.$emit("screenshot", url);
      });
    })
    this.$nextTick(() => {
      this.$emit("get-instance", this.instance);
    });
  },
  beforeDestroy() {
    if (this.instance && this.instance.destroy) {
      this.instance.destroy(false);
    }
  },
};
</script>
